package com.bw.quickadapter;

import androidx.recyclerview.widget.DiffUtil;

import java.util.List;

public class BaseQuickDiff<T> extends DiffUtil.Callback {
    private List<T> sourceData;
    private List<T> nowData;

    public BaseQuickDiff(List<T> sourceData, List<T> nowData) {
        this.sourceData = sourceData;
        this.nowData = nowData;
    }

    @Override
    public int getOldListSize() {
        return sourceData!=null ? sourceData.size() : 0;
    }

    @Override
    public int getNewListSize() {
        return  nowData != null ?nowData.size() : 0;
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return sourceData.get(oldItemPosition)==nowData.get(newItemPosition);
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return sourceData.get(oldItemPosition).toString().equals(nowData.get(oldItemPosition).toString());
    }
}
